home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 11492 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: solon.com!not-for-mail
  2. From: wkaufman@us.oracle.com (William Kaufman)
  3. Newsgroups: comp.lang.c,comp.lang.c.moderated
  4. Subject: Re: const pointer confusion...
  5. Date: 24 Mar 1996 11:48:14 -0600
  6. Organization: Oracle Corporation, Redwood Shores CA
  7. Sender: clc@solutions.solon.com
  8. Approved: clc@solutions.solon.com
  9. Message-ID: <4j41su$nrj@solutions.solon.com>
  10. References: <4j06gm$7oa@solutions.solon.com>
  11. NNTP-Posting-Host: solutions.solon.com
  12.  
  13. In article <4j06gm$7oa@solutions.solon.com> "Reed R. Mangino" <mangino@planet.net> writes:
  14. ] Could someone please straighten me out on this:
  15. ] 1) const int *p = 10;
  16. ]     p is a constant pointer to an int, right?
  17.  
  18.     Eh, no, that'd be "int * const p".  The definition above is a
  19. pointer to a constant int.  (Slight difference, but an important one.)
  20.  
  21. ]       While p can be made to
  22. ]     point to something else, *p can never be assigned to, right?
  23.  
  24.     Right.
  25.  
  26. ] 2) int *const p;
  27. ]     p is a pointer to an integer.
  28.  
  29.     "..._constant_ pointer to an integer".
  30.  
  31. ]       *p can be assigned to, but p can
  32. ]     never be made to point to another address in memory, right?
  33.  
  34.     Right.
  35.  
  36. ] 3) int const *p;
  37. ]     What the heck is this?  I can't find anything like this in my 
  38. ]     books, but my compiler thinks everything is hunky doory!???
  39.  
  40.     It's the same as "const int *p"--a pointer to a constant int.  (This
  41. is one thing that bugs me about "const"--you can move it around.  It's
  42. almost like it's both a storage class and a type specifier,...)
  43.  
  44.                                            -- Bill K.
  45.  
  46. Bill Kaufman               | "Made with the finest British attention
  47. wkaufman@us.oracle.com     |  to the wrong details."
  48.                            |                        -- Mark E. Smith
  49.